//
//  RollCollectionViewCell.swift
//  CompareBuying
//
//  Created by 唐先才 on 16/2/3.
//  Copyright © 2016年 唐先才. All rights reserved.
//

import UIKit

class RollCollectionViewCell: UICollectionViewCell {

    var dataArray: NSMutableArray = []
    var view: AdView?
    var waitView: WaitLoadView?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.createUI()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    func createUI() {
        view = AdView(frame: CGRect(x: 0, y: 0, width: WIDTH, height: 200))
        guard let view = self.view else {
            print("调用自定义的View失败")
            return
        }
        view.backgroundColor = UIColor.whiteColor()
        self.addSubview(view)
        waitView = WaitLoadView(frame: self.contentView.frame)
        guard let waitView = self.waitView else {
            print("滚动视图调用正在加载失败")
            return
        }
        self.addSubview(waitView)
        
    }
    
    func passDataArray(dataArray: NSMutableArray) {
        guard let view = self.view else {
            print("调用自定义的View失败")
            return
        }
        guard let waitView = self.waitView else {
            print("滚动视图调用正在加载失败")
            return
        }
        waitView.removeFromSuperview()
        view.configWithArray(dataArray)
    }
    
    static func rollCollectionViewCellWithCollectionView(collectionView: UICollectionView, dataArray: NSMutableArray, indexPath: NSIndexPath)->UICollectionViewCell {
        if let rollCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("rollCollectionViewCell", forIndexPath: indexPath) as? RollCollectionViewCell {
            if dataArray.count > 0 {
                rollCollectionViewCell.passDataArray(dataArray)
            }
            return rollCollectionViewCell
        }
        return UICollectionViewCell()
    }
}